﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using Business;
using DTO;
using System.Drawing.Drawing2D;
using DevExpress.XtraGrid.Views.Base;
namespace QuanLyKhachSan
{
    public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public Form1()
        {
            InitializeComponent();
            indexImage = 0;
            xtraTabControl1.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False;
            xtraTabFromLogin.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False;
            xtraTabFromMain.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False;
            timer1.Start();
            imageComboBoxEdit1.SelectedItem = imageComboBoxEdit1.Properties.Items[3];
            showChoose = false;
            panelChoose.Hide();
            showThemes = true;
            barButtonItem4.Enabled = false;
            barButtonItem6.Enabled = false;
            barStaticItem2.Caption = DateTime.Now.Day.ToString()+"/" + DateTime.Now.Month.ToString()+"/" + DateTime.Now.Year.ToString();          
        }
        private bool showThemes;
        private bool showChoose;
        private void button1_Click(object sender, EventArgs e)
        {
            if (showThemes == false)
            {
                panelThemes.Show();
                showThemes = true;
                btnThemes.Text = "OFF";
            }
            else
            {
                panelThemes.Hide();
                showThemes = false;
                btnThemes.Text = "ON";
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (showChoose == false)
            {
                panelChoose.Show();
                showChoose = true;
            }
            else
            {
                panelChoose.Hide();
                showChoose = false;
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            xtraTabControl1.SelectedTabPage = xtraTabPage2;
            lbltitle.Text = "Main From";
            DefaultSort();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            barStaticItem1.Caption = DateTime.Now.ToShortTimeString();
        }
        void DefaultSort()
        {
            galleryControl2.Gallery.Groups.Clear();
            PhongService.GetPhongList();
            LoaiPhongService.GetLoaiPhongList();
            gridControl1.DataSource = LoaiPhongDTO.ListLoaiPhong;
            DevExpress.XtraBars.Ribbon.GalleryItem item;
            DevExpress.XtraBars.Ribbon.GalleryItemGroup group;
            group = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
            group.Caption = "Room Non Users";
            for (int j = 0; j < LoaiPhongDTO.ListLoaiPhong.Count; j++)
            {              
                for (int i = 0; i < PhongDTO.ListPhongDTO.Count; i++)
                {
                    if (PhongDTO.ListPhongDTO[i].MaLoaiPhong == LoaiPhongDTO.ListLoaiPhong[j].MaLoaiPhong)
                    {
                        if (PhongDTO.ListPhongDTO[i].TinhTrang==false)
                        {
                            item = new DevExpress.XtraBars.Ribbon.GalleryItem();
                            item.Tag = i;
                            item.Caption = "Room " + PhongDTO.ListPhongDTO[i].TenPhong;
                            item.Description = "Type " + LoaiPhongDTO.ListLoaiPhong[j].TenLoaiPhong;
                            item.ImageIndex = indexImage ;
                            item.HoverImageIndex = indexImage;
                            group.Items.Add(item);
                            galleryControl2.Gallery.Groups.Add(group);
                        }
                    }
                }
            }
            group = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
            group.Caption = "Room Have Users";
            for (int j = 0; j < LoaiPhongDTO.ListLoaiPhong.Count; j++)
            {
                for (int i = 0; i < PhongDTO.ListPhongDTO.Count; i++)
                {
                    if (PhongDTO.ListPhongDTO[i].MaLoaiPhong == LoaiPhongDTO.ListLoaiPhong[j].MaLoaiPhong)
                    {
                        if (PhongDTO.ListPhongDTO[i].TinhTrang)
                        {
                            item = new DevExpress.XtraBars.Ribbon.GalleryItem();
                            item.Tag = i;
                            item.Caption = "Room" + PhongDTO.ListPhongDTO[i].TenPhong;
                            item.Description = "Type " + LoaiPhongDTO.ListLoaiPhong[j].TenLoaiPhong;
                            item.ImageIndex = indexImage+1;
                            item.HoverImageIndex = indexImage+1;
                            group.Items.Add(item);
                            galleryControl2.Gallery.Groups.Add(group);
                        }
                    }
                }
            }
        }
        private void barQuotes_EditValueChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < LoaiPhongDTO.ListLoaiPhong.Count; i++) 
            {
                if (LoaiPhongDTO.ListLoaiPhong[i].MaLoaiPhong == (string)barQuotes.EditValue)
                {
                    barTypeRoom.Caption = "Type Room: " + LoaiPhongDTO.ListLoaiPhong[i].TenLoaiPhong;
                    barPrice.Caption = "Price: " + LoaiPhongDTO.ListLoaiPhong[i].DonGia.ToString();
                }
            }
        }

        private void barButtonItem7_ItemClick(object sender, ItemClickEventArgs e)
        {
            lbltitle.Text = "Froms List";
            xtraTabControl1.SelectedTabPage = xtraTabPage7;
        }

        private void barButtonItem8_ItemClick(object sender, ItemClickEventArgs e)
        {
            lbltitle.Text = "Froms Main";
            xtraTabControl1.SelectedTabPage = xtraTabPage2;
        }
        private void galleryControlGallery1_ItemDoubleClick(object sender, DevExpress.XtraBars.Ribbon.GalleryItemClickEventArgs e)
        {
            if (PhongDTO.ListPhongDTO[indexRoomCheck].TinhTrang == false)
            {
                xtraTabFromMain.SelectedTabPage = xtraTabPage6;
                ribbonControl2.SelectedPage = ribbonPage2;
            }
            else
            {
                xtraTabFromMain.SelectedTabPage = xtraTabPage8;
                ribbonControl2.SelectedPage = ribbonPage3;
            }
        }
        private int indexImage;
        private void ribbonGalleryBarItem1_GalleryItemCheckedChanged(object sender, DevExpress.XtraBars.Ribbon.GalleryItemEventArgs e)
        {
            try
            {
                if (indexSort == 1)
                {
                    indexImage = (Int16)e.Item.Tag;
                    DefaultSort();
                }
                else
                {
                    if (indexSort == 2)
                    {
                        indexImage = (Int16)e.Item.Tag;
                        RoomTypeSort();
                    }
                    else
                    {
                        if (indexSort == 3)
                        {
                            indexImage = (Int16)e.Item.Tag;
                            StatusSort();
                        }
                    }
                }
            }
            catch
            { }
        }

        private void galleryControlGallery3_ItemCheckedChanged(object sender, DevExpress.XtraBars.Ribbon.GalleryItemEventArgs e)
        {
            defaultBarAndDockingController1.Controller.LookAndFeel.SkinName = (string)e.Item.Tag;
        }

        private void imageComboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (imageComboBoxEdit1.EditValue.ToString() == "Skin")
            {
                defaultBarAndDockingController1.Controller.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            }
            else
            {
                if (imageComboBoxEdit1.EditValue.ToString() == "Flat")
                {
                    defaultBarAndDockingController1.Controller.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;
                }
                else
                {
                    if (imageComboBoxEdit1.EditValue.ToString() == "Office2003")
                    {
                        defaultBarAndDockingController1.Controller.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Office2003;
                    }
                    else
                    {
                        if (imageComboBoxEdit1.EditValue.ToString() == "Style3D")
                        {
                            defaultBarAndDockingController1.Controller.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Style3D;
                        }
                        else
                        {
                            if (imageComboBoxEdit1.EditValue.ToString() == "UltraFlat")
                            {
                                defaultBarAndDockingController1.Controller.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.UltraFlat;
                            }
                        }
                    }
                }
            }

        }

        private void checkButton2_CheckedChanged(object sender, EventArgs e)
        {
            ribbonControl1.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonControlStyle.Office2010;
            checkButton1.Checked = false;
        }

        private void checkButton1_CheckedChanged(object sender, EventArgs e)
        {
            ribbonControl1.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonControlStyle.Office2007;
            checkButton2.Checked = false;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            imageComboBoxEdit1.SelectedItem = imageComboBoxEdit1.Properties.Items[3];
            ribbonControl1.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonControlStyle.Default;
        }

        private void cardView1_CustomDrawCardFieldValue(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            Brush brush = e.Cache.GetGradientBrush(e.Bounds, Color.Aquamarine, Color.DarkGreen, LinearGradientMode.BackwardDiagonal);
            e.Appearance.ForeColor = Color.White;
            e.Appearance.Font = e.Cache.GetFont(e.Appearance.Font, FontStyle.Bold);
            if (e.Column.FieldName == "DonGia")
            {
                brush = e.Cache.GetGradientBrush(e.Bounds, Color.White, Color.SkyBlue, LinearGradientMode.BackwardDiagonal);
                e.Appearance.ForeColor = Color.Indigo;
                e.Appearance.Font = e.Cache.GetFont(e.Appearance.Font, FontStyle.Bold);
            }
            e.Graphics.FillRectangle(brush, e.Bounds);
            e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds);
            e.Handled = true;
        }
        private int indexSort;
        private void RoomTypeSort()
        {
            galleryControl2.Gallery.Groups.Clear();
            DevExpress.XtraBars.Ribbon.GalleryItem item;
            DevExpress.XtraBars.Ribbon.GalleryItemGroup group;
            group = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();          
            for (int i = 0; i < LoaiPhongDTO.ListLoaiPhong.Count; i++) 
            {
                group = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
                group.Caption = "Type "+LoaiPhongDTO.ListLoaiPhong[i].TenLoaiPhong+" Room";
                for (int j = 0; j < PhongDTO.ListPhongDTO.Count; j++)
                {
                    if (PhongDTO.ListPhongDTO[j].TinhTrang == false)
                    {
                        if (PhongDTO.ListPhongDTO[j].MaLoaiPhong == LoaiPhongDTO.ListLoaiPhong[i].MaLoaiPhong)
                        {
                            item = new DevExpress.XtraBars.Ribbon.GalleryItem();
                            item.Caption ="Room "+ PhongDTO.ListPhongDTO[j].TenPhong;
                            item.Tag=j;
                            item.ImageIndex = indexImage ;
                            item.HoverImageIndex = indexImage;
                            item.Description = "Room Non Users";
                            group.Items.Add(item);
                            galleryControl2.Gallery.Groups.Add(group);
                        }
                    }
                }
                for (int j = 0; j < PhongDTO.ListPhongDTO.Count; j++)
                {
                    if (PhongDTO.ListPhongDTO[j].TinhTrang)
                    {
                        if (PhongDTO.ListPhongDTO[j].MaLoaiPhong == LoaiPhongDTO.ListLoaiPhong[i].MaLoaiPhong)
                        {
                            item = new DevExpress.XtraBars.Ribbon.GalleryItem();
                            item.Caption = "Room " + PhongDTO.ListPhongDTO[j].TenPhong;
                            item.Tag = j;
                            item.ImageIndex = indexImage+1;
                            item.HoverImageIndex = indexImage+1;
                            item.Description = "Room Have Users";
                            group.Items.Add(item);
                            galleryControl2.Gallery.Groups.Add(group);
                        }
                    }
                }
            }
        }
        private void StatusSort()
        {
            galleryControl2.Gallery.Groups.Clear();
            DevExpress.XtraBars.Ribbon.GalleryItem item;
            DevExpress.XtraBars.Ribbon.GalleryItemGroup group;
            group = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
            for (int i = 0; i < LoaiPhongDTO.ListLoaiPhong.Count; i++)
            {
                group = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
                group.Caption = "Type " + LoaiPhongDTO.ListLoaiPhong[i].TenLoaiPhong + " Room And Room Non Users";
                for (int j = 0; j < PhongDTO.ListPhongDTO.Count; j++)
                {
                    if (PhongDTO.ListPhongDTO[j].TinhTrang == false)
                    {
                        if (PhongDTO.ListPhongDTO[j].MaLoaiPhong == LoaiPhongDTO.ListLoaiPhong[i].MaLoaiPhong)
                        {
                            item = new DevExpress.XtraBars.Ribbon.GalleryItem();
                            item.Caption = "Room " + PhongDTO.ListPhongDTO[j].TenPhong;
                            item.Tag = j;
                            item.ImageIndex = indexImage;
                            item.HoverImageIndex = indexImage;
                            group.Items.Add(item);
                            galleryControl2.Gallery.Groups.Add(group);
                        }
                    }
                }
            }
            for (int i = 0; i < LoaiPhongDTO.ListLoaiPhong.Count; i++)
            {
                group = new DevExpress.XtraBars.Ribbon.GalleryItemGroup();
                group.Caption = "Type " + LoaiPhongDTO.ListLoaiPhong[i].TenLoaiPhong + " Room And Room Have Users";
                for (int j = 0; j < PhongDTO.ListPhongDTO.Count; j++)
                {
                    if (PhongDTO.ListPhongDTO[j].TinhTrang)
                    {
                        if (PhongDTO.ListPhongDTO[j].MaLoaiPhong == LoaiPhongDTO.ListLoaiPhong[i].MaLoaiPhong)
                        {
                            item = new DevExpress.XtraBars.Ribbon.GalleryItem();
                            item.Caption = "Room " + PhongDTO.ListPhongDTO[j].TenPhong;
                            item.Tag = j;
                            item.ImageIndex = indexImage+1;
                            item.HoverImageIndex = indexImage+1;
                            group.Items.Add(item);
                            galleryControl2.Gallery.Groups.Add(group);
                        }
                    }
                }
            }
        }
        private void ribbonGalleryBarItem2_Gallery_ItemCheckedChanged(object sender, DevExpress.XtraBars.Ribbon.GalleryItemEventArgs e)
        {
            if ((Int16)e.Item.Tag == 1)
            {
                DefaultSort();
                indexSort = 1;
            }
            else
            {
                if ((Int16)e.Item.Tag == 2)
                {
                    RoomTypeSort();
                    indexSort = 2;
                }
                else
                {
                    if ((Int16)e.Item.Tag == 3)
                    {
                        StatusSort();
                        indexSort = 3;
                    }
                }
            }
        }
        private int indexRoomCheck;
        private void galleryControlGallery1_ItemCheckedChanged(object sender, DevExpress.XtraBars.Ribbon.GalleryItemEventArgs e)
        {
            indexRoomCheck = (int)e.Item.Tag;
            if (PhongDTO.ListPhongDTO[indexRoomCheck].TinhTrang)
            {
                barButtonItem4.Enabled = false;
                barButtonItem6.Enabled = true;
            }
            else
            {
                barButtonItem4.Enabled = true;
                barButtonItem6.Enabled = false;
            }
        }

        private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabFromMain.SelectedTabPage = xtraTabPage6;
            ribbonControl2.SelectedPage = ribbonPage2;
        }

        private void barButtonItem6_ItemClick(object sender, ItemClickEventArgs e)
        {
            xtraTabFromMain.SelectedTabPage = xtraTabPage8;
            ribbonControl2.SelectedPage = ribbonPage3;
        }
    }
}
